import cv2 
import os
def main():
    # 打开摄像头

    capture = cv2.VideoCapture(1)

    if not capture.isOpened():
        print("无法打开摄像头.")
        return
    num=0
    while True:
        # 读取视频帧
        ret, frame = capture.read()

        if not ret:
            print("无法获取视频帧.")
            break
        
        # 在窗口中显示帧
        cv2.imshow('Video', frame)
        a=cv2.waitKey(1)
        if a==13:
            ret=cv2.imwrite('calibration/cam_clib/pictures/'+str(num)+'.jpg',frame)
            if ret:
                print('calibration/cam_clib/pictures/'+str(num)+'.jpg'+'保存成功','shape:',frame.shape)
                num+=1
            else:
                print('保存失败')
                
        # 检查按键，按下 'q' 键退出循环
        if a ==27:
            break

    # 释放摄像头资源
    capture.release()
    cv2.destroyAllWindows()

if __name__ == "__main__":
    main()